package com.example.direct.service;

import jakarta.annotation.Resource;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * ClassName:MessageService
 * Package:com.example.direct.service
 * Description:
 *
 * @Author:ZhangXin
 * @Create:2023/8/11-15:31
 * @Version:v1.0
 */
@Service
@Slf4j
public class MessageService {

    @Resource
    private RabbitTemplate rabbitTemplate;

    public void sendMsg() {
        Message message = MessageBuilder.withBody("直连交换机".getBytes()).build();
        //参数 交换机 路由key 消息
        rabbitTemplate.convertAndSend("exchange.direct", "info", message);
        log.info("消息发送完毕，发送时间为：{}", new Date());
    }
}
